home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 2 / CD ACTUAL VOL 2.iso / docs / kernel-h < prev    next >
Encoding:
Text File  |  1995-09-10  |  41.8 KB  |  1,234 lines

  1.   The Linux Kernel HOWTO
  2.   Brian Ward, ward@blah.tu-graz.ac.at
  3.   v0.31, 31 March 1995
  4.  
  5.   This is a detailed guide to kernel configuration, compilation, and
  6.   upgrades.
  7.  
  8.   1.  Introduction
  9.  
  10.  
  11.   This is release 0.31 of the Kernel-HOWTO. Should you read this
  12.   document?  Well, see if you've got any of the following symptoms:
  13.  
  14.  
  15.  
  16.   o  ``Arg! This wizzo-46.5.6 package says it needs kernel release
  17.      1.1.193 and I still only have release 1.0.9!''
  18.  
  19.   o  There's a device driver in one of the newer kernels that you just
  20.      gotta have
  21.  
  22.   o  You really have no idea at all how to compile a kernel
  23.  
  24.   o  ``Is this stuff in the README really the whole story?''
  25.  
  26.   o  You came, you tried, it didn't work
  27.  
  28.   o  You know how to compile and install a kernel, and people seem to
  29.      know this. Therefore, they keep whining to you to help them install
  30.      their kernels.
  31.  
  32.  
  33.   1.1.  Read this first! (I mean it)
  34.  
  35.   Some of the examples in this document assume that you have GNU tar,
  36.   find, and xargs. These are quite standard; this should not cause
  37.   problems. It is also assumed that you know your system's filesystem
  38.   structure; if you don't, it is critical that you keep a written copy
  39.   of the mount command's output during normal system operation (or a
  40.   listing of /etc/fstab, if you can read it). This information is
  41.   important, and does not change unless you repartition your disk, add a
  42.   new one, reinstall your system, or something similar.
  43.  
  44.  
  45.   The latest kernel version at the time of this writing was 1.2.2,
  46.   meaning that the references and examples correspond to that release.
  47.   Even though I try to make this document as version-independent as
  48.   possible, the kernel is constantly under development, so if you get a
  49.   newer release, it will inevitably have some differences. Again, this
  50.   should not cause major problems, but it may create some confusion.
  51.  
  52.  
  53.  
  54.   1.2.  A word on style
  55.  
  56.   Text that looks like this is either something that appears on your
  57.   screen, a filename, or something that can be directly typed in, such
  58.   as a command, or options to a command (if you're looking at a plain-
  59.   text file, it doesn't look any different). Commands and other input
  60.   are frequently quoted (with ` '), which causes the following classic
  61.   punctuation problem: if such an item appears at the end of a sentence
  62.   in quotes, people often type a `.' along with the command, because the
  63.   American quoting style says to put the period inside of the quotation
  64.   marks. Even though common sense should tell one to strip off the
  65.   punctuation first, many people simply do not remember, so I will place
  66.   it outside the quotation marks in such cases. For example, I would
  67.   write `make config', not `make config.'
  68.  
  69.  
  70.   2.  Important questions and their answers
  71.  
  72.  
  73.  
  74.   2.1.  What does the kernel do, anyway?
  75.  
  76.  
  77.   The Unix kernel acts as a mediator for your programs. First, it does
  78.   the memory management for all of the running programs (processes), and
  79.   makes sure that they all get a fair (or unfair, if you please) share
  80.   of the processor's cycles. In addition, it provides a nice, fairly
  81.   portable interface for programs to talk to your hardware.
  82.  
  83.  
  84.   Obviously, there is more to the kernel's operation than this, but the
  85.   basic functions above are the most important to know.
  86.  
  87.  
  88.  
  89.   2.2.  Why would I want to upgrade my kernel?
  90.  
  91.  
  92.   Newer kernels generally offer the ability to talk to more types of
  93.   hardware (that is, they have more device drivers), they can have
  94.   better process management, they can run faster than the older
  95.   versions, they could be more stable than the older versions, and they
  96.   fix silly bugs in the older versions. Most people upgrade kernels
  97.   because they want the device drivers and the bug fixes.
  98.  
  99.  
  100.  
  101.   2.3.  What kind of hardware do the newer kernels support?
  102.  
  103.  
  104.   See the Hardware-HOWTO. Alternatively, you can look at the `config.in'
  105.   file in the linux source, or just find out when you try `make config'.
  106.   This shows you all hardware supported by the standard kernel
  107.   distribution, but not everything that linux supports; many common
  108.   device drivers (such as the PCMCIA drivers and some tape drivers) are
  109.   loadable modules maintained and distributed separately.
  110.  
  111.  
  112.  
  113.   2.4.  What version of gcc and libc do I need?
  114.  
  115.  
  116.   Linus recommends a version of gcc in the README file included with the
  117.   linux source. If you don't have this version, the documentation in the
  118.   recommended version of gcc should tell you if you need to upgrade your
  119.   libc.  This is not a difficult procedure, but it is important to
  120.   follow the instructions.
  121.  
  122.  
  123.  
  124.   2.5.  What's a loadable module?
  125.  
  126.  
  127.   These are pieces of kernel code which are not linked (included)
  128.   directly in the kernel. One compiles them separately, and can insert
  129.   and remove them into the running kernel at almost any time. Due to its
  130.   flexibility, this is now the preferred way to code certain kernel
  131.   features. Many popular device drivers, such as the PCMCIA drivers and
  132.   the QIC-80/40 tape driver, are loadable modules.
  133.   2.6.  How much disk space do I need?
  134.  
  135.  
  136.   It depends on your particular system configuration. First, the
  137.   compressed linux source is 2.35 megabytes large at version 1.2.0. Most
  138.   keep this even after unpacking.  Uncompressed, it takes up 10 MB. But
  139.   that's not the end -- you need more to actually compile the thing.
  140.   This depends on how much you configure into your kernel. For example,
  141.   on my 386, I have networking, the 3Com 3C503 driver, and five
  142.   filesystems configured, using 18 MB. Adding the compressed linux
  143.   source, you need about 20 MB for this particular configuration. On
  144.   another system, without network device support (but still with
  145.   networking support), and sound card support, it consumes 14 MB. Also,
  146.   a newer kernel is certain to have a larger source tree than an older
  147.   one, so, in general, if you have a lot of hardware, make sure that you
  148.   have a big enough hard disk in that mess.
  149.  
  150.  
  151.  
  152.   2.7.  How long does it take?
  153.  
  154.  
  155.   For most people, the answer is ``fairly long.'' The speed of your
  156.   system and the amount of memory you have ultimately determines the
  157.   time, but there is a small bit to do with the amount of stuff you
  158.   configure into the kernel. On a 486DX4/100 notebook with 16 MB of RAM,
  159.   on a kernel with five filesystems, networking support, and sound card
  160.   drivers, it takes under 20 minutes. On a 386DX/40 (8 MB RAM) with a
  161.   similar configuration, compilation lasts nearly 1.5 hours. It is a
  162.   generally good recommendation to make a little coffee, watch some TV,
  163.   knit, or whatever you do for fun while your machine compiles the
  164.   kernel.
  165.  
  166.  
  167.  
  168.   3.  How to actually configure the kernel
  169.  
  170.  
  171.  
  172.   3.1.  Getting the source
  173.  
  174.  
  175.   You can obtain the source via anonymous ftp from ftp.funet.fi in
  176.   /pub/OS/Linux/PEOPLE/Linus, a mirror, or other sites.  It is typically
  177.   labelled linux-x.y.z.tar.gz, where x.y.z is the version number. Newer
  178.   (better?) versions and the patches are typically in subdirectories
  179.   such as `v1.1' and `v1.2' The highest number is the latest version,
  180.   and is usually a ``test release,'' meaning that if you feel uneasy
  181.   about beta or alpha releases, you should stay with a major release.
  182.  
  183.  
  184.   I strongly suggest that you use a mirror ftp site instead of
  185.   ftp.funet.fi. Here is a short list of mirrors and other sites:
  186.  
  187.  
  188.   USA:            tsx-11.mit.edu:/pub/linux/sources/system
  189.   USA:            sunsite.unc.edu:/pub/Linux/kernel
  190.   UK:             unix.hensa.ac.uk:/pub/linux/kernel
  191.   Austria:        fvkma.tu-graz.ac.at:/pub/linux/linus
  192.   Germany:        ftp.Germany.EU.net:/pub/os/Linux/Local.EUnet/Kernel/Linus
  193.   Germany:        ftp.dfv.rwth-aachen.de:/pub/linux/kernel
  194.   France:         ftp.ibp.fr:/pub/linux/sources/system/patches
  195.   Australia:      kirk.bond.edu.au:/pub/OS/Linux/kernel
  196.  
  197.  
  198.  
  199.   If you do not have ftp access, a list of BBS systems which carry linux
  200.   is posted periodically to comp.os.linux.announce; try to obtain this.
  201.  
  202.  
  203.  
  204.   3.2.  Unpacking the source
  205.  
  206.  
  207.   Log in as or su to `root', and cd to /usr/src.  If you installed
  208.   kernel source when you first installed linux (as most do), there will
  209.   already be a directory called `linux' there, which contains the entire
  210.   old source tree.  If you have the disk space and you want to play it
  211.   safe, preserve that directory. A good idea is to figure out what
  212.   version your system runs now and rename the directory accordingly. The
  213.   command `uname -r' prints the current kernel version.  Therefore, if
  214.   `uname -r' said `1.1.47', you would rename (with `mv') `linux' to
  215.   `linux-1.1.47'.  If you feel mildly reckless, just wipe out the entire
  216.   directory. In any case, make certain there is no `linux' directory in
  217.   /usr/src before unpacking the full source code.
  218.  
  219.  
  220.   Now, in /usr/src, unpack the source with `tar zxvf linux-x.y.z.tar.gz'
  221.   (if you've just got a .tar  file with no .gz at the end, `tar xvf
  222.   linux-x.y.z.tar' works.).  The contents of the source will fly by.
  223.   When finished, there will be a new `linux' directory in /usr/src. cd
  224.   to linux and look over the README  file.  There will be a section with
  225.   the label `INSTALLING the kernel'.  Carry out the instructions when
  226.   appropriate -- symbolic links that should be in place, removal of
  227.   stale .o files, etc.
  228.  
  229.  
  230.  
  231.   3.3.  Configuring the kernel
  232.  
  233.  
  234.   Note: Some of this is reiteration/clarification of a similar section
  235.   in Linus' README file.
  236.  
  237.  
  238.   The command `make config' while in /usr/src/linux starts a configure
  239.   script which asks you many questions. It requires bash, so verify that
  240.   bash is /bin/bash, /bin/sh, or $BASH.
  241.  
  242.  
  243.   You are ready to answer the questions, usually with `y' (yes) or `n'
  244.   (no). Some of the more obvious and non-critical options are not
  245.   described here; see the section ``Other configuration options'' for
  246.   short descriptions of a few others.
  247.  
  248.  
  249.  
  250.   3.3.1.  Kernel math emulation
  251.  
  252.  
  253.   If you don't have a math coprocessor (you have a bare 386 or 486SX),
  254.   you must say `y' to this. If you do have a coprocessor and you still
  255.   say `y', don't worry too much -- the coprocessor is still used and the
  256.   emulation ignored. The only consequence is that the kernel will be
  257.   larger (costing RAM).
  258.  
  259.  
  260.  
  261.   3.3.2.  Normal (MFM/RLL) disk and IDE disk/cdrom support
  262.  
  263.  
  264.  
  265.   You probably need to support this; it means that the kernel will
  266.   support standard PC hard disks, which most people have. This driver
  267.   does not include SCSI drives; they come later in the configuration.
  268.  
  269.   You will then be asked about the ``old disk-only'' and ``new IDE''
  270.   drivers.  You want to choose one of them; the main difference is that
  271.   the old driver only supports two disks on a single interface, and the
  272.   new one supports a secondary interface and IDE/ATAPI cdrom drives. The
  273.   new driver is 4k larger than the old one and is also supposedly
  274.   ``improved,'' meaning that aside from containing a different number of
  275.   bugs, it might improve your disk performance, especially if you have
  276.   newer hardware.
  277.  
  278.  
  279.  
  280.   3.3.3.  Networking support
  281.  
  282.  
  283.   In principle, you would only say `y' if your machine is on a network
  284.   such as the internet, or you want to use SLIP, PPP, term, etc to dial
  285.   up for internet access. However, as many packages (such as X windows)
  286.   require networking support even if your machine does not live on a
  287.   real network, you should say `y'. Later on, you will be asked if you
  288.   want to support TCP/IP networking; again, say `y' here if you are not
  289.   absolutely sure.
  290.  
  291.  
  292.  
  293.   3.3.4.  Limit memory to low 16MB
  294.  
  295.  
  296.   There exist buggy 386 DMA controllers which have problems with
  297.   addressing anything more than 16 MB of RAM; you want to say `y' in the
  298.   (rare) case that you have one.
  299.  
  300.  
  301.  
  302.   3.3.5.  System V IPC
  303.  
  304.  
  305.   One of the best definitions of IPC (Interprocess Communication) is in
  306.   the Perl book's glossary. Not surprisingly, Perl employs it to let
  307.   processes talk to each other, as well as many other packages, so it is
  308.   not a good idea to say n unless you know exactly what you are doing.
  309.  
  310.  
  311.  
  312.   3.3.6.  Use -m486 flag for 486-specific optimizations
  313.  
  314.  
  315.   This optimizes the kernel for use on a 486 processor. The new kernel
  316.   will be slightly larger, but will work fine on a 386.
  317.  
  318.  
  319.  
  320.   3.3.7.  SCSI support
  321.  
  322.  
  323.   If you have a SCSI device, say `y'. You will be prompted for further
  324.   information, such as support for CD-ROM, disks, and what kind of SCSI
  325.   adapter you have. See the SCSI-HOWTO for greater detail.
  326.  
  327.  
  328.  
  329.  
  330.  
  331.   3.3.8.  Network device support
  332.  
  333.  
  334.   If you have a network card, or you would like to use SLIP, PPP, or a
  335.   parallel port adapter, say `y'. The config script will prompt for
  336.   which kind of card you have, and which protocol to use.
  337.  
  338.  
  339.  
  340.   3.3.9.  Filesystems
  341.  
  342.  
  343.   The configure script then asks if you wish to support the following
  344.   filesystems:
  345.  
  346.  
  347.   Standard (minix) - Newer distributions don't create minix filesystems,
  348.   and many people don't use it, but it may still be a good idea to
  349.   configure this one. Some ``rescue disk'' programs use it, and still
  350.   more floppies may have a minix filesystem, since the minix filesystem
  351.   is fairly optimal for floppy disks.
  352.  
  353.  
  354.   Extended fs - This was the first version of the extended filesystem,
  355.   which is no longer in widespread use. Chances are, you'll know it if
  356.   you need it.
  357.  
  358.  
  359.   Second extended - This is widely used in new distributions. You
  360.   probably have one of these, and need to say `y'.
  361.  
  362.  
  363.   xiafs filesystem - At one time, this was not uncommon, but at the time
  364.   of this writing, I did not know of anyone using it.
  365.  
  366.  
  367.   msdos - If you want to use your MS-DOS hard disk partitions, or mount
  368.   MS-DOS formatted floppy disks, say `y'.
  369.  
  370.  
  371.   umsdos - This filesystem expands an MS-DOS filesystem with usual Unix-
  372.   like features such as long filenames. It is not useful for people
  373.   (like me) who ``don't do DOS.''
  374.  
  375.  
  376.   /proc - Another one of the greatest things since powdered milk (idea
  377.   shamelessly stolen from Bell Labs, I guess). One doesn't make a proc
  378.   filesystem on a disk; this is a filesystem interface to the kernel and
  379.   processes. Many process listers (such as `ps') use it. Try `cat
  380.   /proc/meminfo' or `cat /proc/devices' sometime.  Some shells (rc, in
  381.   particular) use /proc/self/fd  (known as /dev/fd on other systems) for
  382.   I/O. You should almost certainly say `y' to this; many important linux
  383.   tools depend on it.
  384.  
  385.  
  386.   NFS - If your machine lives on a network and you want to share files
  387.   with other systems using NFS, say `y'.
  388.  
  389.  
  390.   ISO9660 - Found on most CD-ROMs.
  391.  
  392.  
  393.   OS/2 HPFS - At the time of this writing, a read-only fs for OS/2 HPFS.
  394.  
  395.  
  396.  
  397.   System V and Coherent - for partitions of System V and Coherent
  398.   systems (These are other PC Unix variants).
  399.  
  400.  
  401.  
  402.   3.3.9.1.  But I don't know which filesystems I need!
  403.  
  404.  
  405.   Ok, type `mount'. The output will look something like this:
  406.  
  407.  
  408.  
  409.  
  410.                blah# mount
  411.                /dev/hda1 on / type ext2 (defaults)
  412.                /dev/hda3 on /usr type ext2 (defaults)
  413.                none on /proc type proc (defaults)
  414.                /dev/fd0 on /mnt type msdos (defaults)
  415.  
  416.  
  417.  
  418.  
  419.   Look at each line; the word next to `type' is the filesystem type. In
  420.   this example, my /  and /usr filesystems are second extended, I'm
  421.   using /proc, and there's a floppy disk mounted using the msdos (bleah)
  422.   filesystem.
  423.  
  424.   You can try `cat /proc/filesystems' if you have /proc currently
  425.   enabled; it will list your current kernel's filesystems.
  426.  
  427.   The configuration of rarely-used, non-critical filesystems can cause
  428.   kernel bloat; see the section on modules for a way to avoid this.
  429.  
  430.  
  431.  
  432.   3.3.10.  Character devices
  433.  
  434.  
  435.   Here, you enable the drivers for your printer, busmouse, PS/2 mouse
  436.   (many notebooks use the PS/2 mouse protocol for their built-in
  437.   trackballs), some tape drives, and other such ``character'' devices.
  438.   Say `y' when appropriate.
  439.  
  440.  
  441.   Note: Selection is a program which allows the use of the mouse outside
  442.   of X Windows for cut and paste between virtual consoles. It's fairly
  443.   nice if you have a serial mouse, because it coexists well with X
  444.   Windows, but you need to do special tricks for others. Selection
  445.   support was a configuration option at one time, but is now standard.
  446.  
  447.  
  448.  
  449.   3.3.11.  Sound card
  450.  
  451.  
  452.   If you feel a great desire to hear biff bark, say `y', and later on,
  453.   another config program will compile and ask you all about your sound
  454.   board. (A note on sound card configuration: when it asks you if you
  455.   want to install the full version of the driver, you can say `n' and
  456.   save some kernel memory by picking only the features which you deem
  457.   necessary.)
  458.  
  459.  
  460.  
  461.  
  462.  
  463.   3.3.12.  Kernel hacking
  464.  
  465.  
  466.   >From Linus' README:
  467.  
  468.   the ``kernel hacking'' configuration details usually result in a
  469.   bigger or slower kernel (or both), and can even make the kernel less
  470.   stable by configuring some routines to actively try to break bad code
  471.   to find kernel problems (kmalloc()).  Thus you should probably answer
  472.   `n' to the questions for a ``production'' kernel.
  473.  
  474.  
  475.  
  476.   3.4.  Now what? (The Makefile)
  477.  
  478.  
  479.   After you make config, a message tells you that your kernel has been
  480.   configured, and to ``check the top-level Makefile for additional
  481.   configuration,'' etc.
  482.  
  483.  
  484.   So, look at the Makefile. You probably will not need to change it, but
  485.   it never hurts to look. You can also change its options with the
  486.   `rdev' command once the new kernel is in place.
  487.  
  488.  
  489.  
  490.   4.  Compiling the kernel
  491.  
  492.  
  493.  
  494.   4.1.  Cleaning and depending
  495.  
  496.  
  497.   When the configure script ends, it also tells you to `make dep' and
  498.   `clean'.  So, do the `make dep'. This insures that all of the
  499.   dependencies, such the include files, are in place. It does not take
  500.   long, unless your computer is fairly slow to begin with.  When
  501.   finished, do a `make clean'.  This removes all of the object files and
  502.   some other things that an old version leaves behind. Don't forget this
  503.   step.
  504.  
  505.  
  506.  
  507.   4.2.  Compile time
  508.  
  509.  
  510.   After depending and cleaning, you may now `make zImage' or `make
  511.   zdisk' (This is the part that takes a long time.)  `make zImage' will
  512.   compile the kernel, and leave a file in arch/i386/boot called `zImage'
  513.   (among other things). This is the new compressed kernel. `make zdisk'
  514.   does the same thing, but also places the new zImage on a floppy disk
  515.   which you hopefully put in drive ``A:''.  `zdisk' is fairly handy for
  516.   testing new kernels; if it bombs (or just doesn't work right), just
  517.   remove the floppy and boot with your old kernel. It can also be a
  518.   handy way to boot if you accidentally remove your kernel (or something
  519.   equally as dreadful). You can also use it to install new systems when
  520.   you just dump the contents of one disk onto the other (``all this and
  521.   more! NOW how much would you pay?'').
  522.  
  523.  
  524.   All reasonably recent kernels are compressed, hence the `z' in front
  525.   of the names. A compressed kernel automatically decompresses itself
  526.   when executed.
  527.  
  528.  
  529.   4.3.  Other ``make''ables
  530.  
  531.  
  532.   `make mrproper' will do a more extensive `clean'ing.  It is sometimes
  533.   necessary; you may wish to do it at every patch. See the section on
  534.   modules for a description of `make modules'.
  535.  
  536.  
  537.   4.4.  Installing the kernel
  538.  
  539.   After you have a new kernel that seems to work the way you want it to,
  540.   it's time to install it. Most people use LILO (Linux Loader) for this.
  541.   `make zlilo' will install the kernel, run LILO on it, and get you all
  542.   ready to boot, BUT ONLY if lilo is configured in the following way on
  543.   your system: kernel is /vmlinuz, lilo is in /sbin, and your lilo
  544.   config (/etc/lilo.conf) agrees with this.
  545.  
  546.  
  547.   Otherwise, you need to use LILO directly. It's a fairly easy package
  548.   to install and work with, but it has a tendency to confuse people with
  549.   the configuration file.  Look at the config file (either
  550.   /etc/lilo/config for older versions or /etc/lilo.conf for new
  551.   versions), and see what the current setup is. The config file looks
  552.   like this:
  553.  
  554.  
  555.  
  556.       image = /vmlinuz
  557.           label = Linux
  558.           root = /dev/hda1
  559.           ...
  560.  
  561.  
  562.  
  563.   The `image =' is set to the currently installed kernel.  Most people
  564.   use /vmlinuz. `label' is used by lilo to determine which kernel or
  565.   operating system to boot, and `root' is the / of that particular
  566.   operating system. Make a backup copy of your old kernel and copy the
  567.   zImage which you just made into place (you would say `cp zImage
  568.   /vmlinuz' if you use `/vmlinuz').  Then, rerun lilo -- on newer
  569.   systems, you can just run `lilo', but on older stuff, you might have
  570.   to do an /etc/lilo/install or even an /etc/lilo/lilo -C
  571.   /etc/lilo/config.
  572.  
  573.  
  574.   If you would like to know more about LILO's configuration, or you
  575.   don't have LILO, get the newest version from your favorite ftp site
  576.   and follow the instructions.
  577.  
  578.  
  579.   To boot one of your old kernels off the hard disk (another way to save
  580.   yourself in case you screw up the new kernel), copy the lines below
  581.   (and including) `image = xxx' in the LILO config file to the bottom of
  582.   the file, and change the `image = xxx' to `image = yyy', where `yyy'
  583.   is the full pathname of the file you saved your backup kernel to.
  584.   Then, change the `label = zzz' to `label = linux-backup' and rerun
  585.   lilo. You may need to put a line in the config file saying `delay=x',
  586.   where x is an amount in tenths of a second, which tells LILO to wait
  587.   that much time before booting, so that you can interrupt it (with the
  588.   shift key, for example), and type in the label of the backup boot
  589.   image (in case unpleasant things happen).
  590.  
  591.  
  592.  
  593.  
  594.  
  595.   5.  Patching the kernel
  596.  
  597.  
  598.  
  599.   5.1.  Applying a patch
  600.  
  601.  
  602.   Incremental upgrades of the kernel are distributed as patches. For
  603.   example, if you have version 1.1.45, and you notice that there's a
  604.   `patch46.gz' out there for it, it means you can upgrade to version
  605.   1.1.46 through application of the patch. You might want to make a
  606.   backup of the source tree first (`make clean' and then `cd /usr/src;
  607.   tar zcvf old-tree.tar.gz linux' will make a compressed tar archive for
  608.   you.).
  609.  
  610.  
  611.   So, continuing with the example above, let's suppose that you have
  612.   `patch46.gz' in /usr/src. cd to /usr/src  and do a `zcat patch46.gz |
  613.   patch -p0' (or `patch -p0 < patch46' if the patch isn't compressed).
  614.   You'll see things whizz by (or flutter by, if your system is that
  615.   slow) telling you that it is trying to apply hunks, and whether it
  616.   succeeds or not. Usually, this action goes by too quickly for you to
  617.   read, and you're not too sure whether it worked or not, so you might
  618.   want to use the -s flag to patch, which tells patch to only report
  619.   error messages (you don't get as much of the ``hey, my computer is
  620.   actually doing something for a change!'' feeling, but you may prefer
  621.   this..). To look for parts which might not have gone smoothly, cd to
  622.   /usr/src/linux  and look for files with a .rej extension. Some
  623.   versions of patch (older versions which may have been compiled with on
  624.   an inferior filesystem) leave the rejects with a # extension. You can
  625.   use `find' to look for you;
  626.  
  627.   find .  -name '*.rej' -print
  628.  
  629.  
  630.   prints all files who live in the current directory or any subdirecto-
  631.   ries with a .rej extension to the standard output.
  632.  
  633.  
  634.   If everything went right, do a `make clean', `config', and `dep' as
  635.   described in sections 3 and 4.
  636.  
  637.  
  638.   There are quite a few options to the patch command. As mentioned
  639.   above, patch -s will suppress all messages except the errors. If you
  640.   keep your kernel source in some other place than /usr/src/linux, patch
  641.   -p1 (in that directory) will patch things cleanly. Other patch options
  642.   are well-documented in the manual page.
  643.  
  644.  
  645.  
  646.   5.2.  If something goes wrong
  647.  
  648.  
  649.   The most frequent problem that used to arise was when a patch modified
  650.   a file called `config.in' and it didn't look quite right, because you
  651.   changed the options to suit your machine. This has been taken care of,
  652.   but one still might encounter it with an older release.  To fix it,
  653.   look at the config.in.rej  file, and see what remains of the original
  654.   patch.  The changes will typically be marked with `+' and `-' at the
  655.   beginning of the line. Look at the lines surrounding it, and remember
  656.   if they were set to `y' or `n'. Now, edit config.in, and change `y' to
  657.   `n' and `n' to `y' when appropriate. Do a
  658.  
  659.   patch -p0 < config.in.rej
  660.  
  661.   and if it reports that it succeeded (no fails), then you can continue
  662.   on with a configuration and compilation. The config.in.rej file will
  663.   remain, but you can get delete it.
  664.  
  665.  
  666.   If you encounter further problems, you might have installed a patch
  667.   out of order. If patch says `previously applied patch detected: Assume
  668.   -R?', you are probably trying to apply a patch which is below your
  669.   current version number; if you answer `y', it will attempt to degrade
  670.   your source, and will most likely fail; thus, you will need to get a
  671.   whole new source tree (which might not have been such a bad idea in
  672.   the first place).
  673.  
  674.  
  675.   To back out (unapply) a patch, use `patch -R' on the original patch.
  676.  
  677.  
  678.   The best thing to do when patches really turn out wrong is to start
  679.   over again with a clean, out-of-the-box source tree (for example, from
  680.   one of the linux-x.y.z.tar.gz  files), and start again.
  681.  
  682.  
  683.  
  684.   5.3.  Getting rid of the .orig files
  685.  
  686.  
  687.   After just a few patches, the .orig  files will start to pile up. For
  688.   example, one 1.1.51 tree I had was once last cleaned out at 1.1.48.
  689.   Removing the .orig files saved over a half a meg.
  690.  
  691.   find .  -name '*.orig' -exec rm -f {} ';'
  692.  
  693.  
  694.   will take care of it for you. Versions of patch which use # for
  695.   rejects use a tilde instead of .orig.
  696.  
  697.   There are better ways to get rid of the .orig files, which depend on
  698.   GNU xargs:
  699.  
  700.   find .  -name '*.orig' | xargs rm
  701.  
  702.  
  703.   or the ``quite secure but a little more verbose'' method:
  704.  
  705.   find . -name '*.orig' -print0 | xargs --null rm --
  706.  
  707.  
  708.  
  709.  
  710.  
  711.   5.4.  Other patches
  712.  
  713.  
  714.   There are other patches (I'll call them ``nonstandard'') than the ones
  715.   Linus distributes. If you apply these, Linus' patches may not work
  716.   correctly and you'll have to either back them out, fix the source or
  717.   the patch, install a new source tree, or a combination of the above.
  718.   This can become very frustrating, so if you do not want to modify the
  719.   source (with the possibility of a very bad outcome), back out the
  720.   nonstandard patches before applying Linus', or just install a new
  721.   tree. Then, you can see if the nonstandard patches still work. If they
  722.   don't, you are either stuck with an old kernel, playing with the patch
  723.   or source to get it to work, or waiting (possibly begging) for a new
  724.   version of the patch to come out.
  725.  
  726.  
  727.   How common are the patches not in the standard distribution? You will
  728.   probably hear of them. I use the noblink patch for my virtual consoles
  729.   because I hate blinking cursors (This patch is frequently updated for
  730.   new kernel releases.).
  731.  
  732.  
  733.  
  734.   6.  Additional packages
  735.  
  736.   Your linux kernel has many features which are not explained in the
  737.   kernel source itself; these features are typically utilized through
  738.   external packages. Some of the most common are listed here.
  739.  
  740.  
  741.  
  742.   6.1.  kbd
  743.  
  744.   The linux console probably has more features than it deserves. Among
  745.   these are the ability to switch fonts, remap your keyboard, switch
  746.   video modes (in newer kernels), etc. The kbd package has programs
  747.   which allow the user to do all of this, plus many fonts and keyboard
  748.   maps for almost any keyboard, and is available from the same sites
  749.   that carry the kernel source.
  750.  
  751.  
  752.  
  753.   6.2.  util-linux
  754.  
  755.   Rik Faith (faith@cs.unc.edu) keeps a large collection of linux
  756.   utilities which are, by odd coincidence, called util-linux. Available
  757.   via anonymous ftp from sunsite.unc.edu in /pub/Linux/system/Misc, it
  758.   contains programs such as setterm, rdev, and ctrlaltdel, which are
  759.   relevant to the kernel. As Rik says, do not install without thinking;
  760.   you do not need to install everything in the package, and it could
  761.   very well cause serious problems if you do.
  762.  
  763.  
  764.  
  765.   6.3.  hdparm
  766.  
  767.   As with many packages, this was once a kernel patch and support
  768.   programs.  The patches made it into the official kernel, and the
  769.   programs to optimize and play with your hard disk are distributed
  770.   separately.
  771.  
  772.  
  773.  
  774.   7.  Some pitfalls
  775.  
  776.  
  777.  
  778.   7.1.  make clean
  779.  
  780.  
  781.   If your new kernel does really weird things after a routine kernel
  782.   upgrade, chances are you forgot to make clean before compiling the new
  783.   kernel. Symptoms can be anything from your system outright crashing,
  784.   strange I/O problems, to crummy performance. Make sure you do a make
  785.   dep, too.
  786.  
  787.  
  788.  
  789.   7.2.  Huge or slow kernels
  790.  
  791.  
  792.  
  793.   If your kernel is sucking up a lot of memory, is too large, or just
  794.   takes forever to compile even when you've got your new 486DX6/440
  795.   working on it, you've probably got lots of unneeded stuff (device
  796.   drivers, filesystems, etc) configured. If you don't use it, don't
  797.   configure it, because it does take up memory.  The most obvious
  798.   symptom of kernel bloat is extreme swapping in and out of memory to
  799.   disk; if your disk is making a lot of noise, look over your kernel
  800.   configuration.
  801.  
  802.  
  803.   You can find out how much memory the kernel is using by taking the
  804.   total amount of memory in your machine and subtracting it from the
  805.   amount of ``total mem'' in /proc/meminfo  or the output of the command
  806.   `free'. You can also find out by doing a `dmesg' (or by looking at the
  807.   kernel log file, wherever it is on your system).  There will be a line
  808.   which looks like this:
  809.  
  810.  
  811.   Memory: 15124k/16384k available (552k kernel code, 384k reserved, 324k
  812.   data)
  813.  
  814.  
  815.   My 386 (which has slightly less junk configured) says this:
  816.  
  817.  
  818.   Memory: 7000k/8192k available (496k kernel code, 384k reserved, 312k
  819.   data)
  820.  
  821.  
  822.  
  823.   7.3.  Kernel doesn't compile
  824.  
  825.  
  826.   If it does not compile, then it is likely that a patch failed, or your
  827.   source is somehow corrupt. Your version of gcc also might not be
  828.   correct, or could also be corrupt (for example, the include files
  829.   might be in error). Make sure that the symbolic links which Linus
  830.   describes in the README are set up correctly. In general, if a
  831.   standard kernel does not compile, something is seriously wrong with
  832.   the system, and reinstallation of certain tools is probably necessary.
  833.  
  834.  
  835.  
  836.   7.4.  New version of the kernel doesn't seem to boot
  837.  
  838.  
  839.   You did not run LILO, or it is not configured correctly. One thing
  840.   that ``got'' me once was a problem in the config file; it said `boot =
  841.   /dev/hda1' instead of `boot = /dev/hda' (This can be really annoying
  842.   at first, but once you have a working config file, you shouldn't need
  843.   to change it.).
  844.  
  845.  
  846.  
  847.   7.5.  You forgot to run LILO, or system doesn't boot at all
  848.  
  849.  
  850.   Ooops! The best thing you can do here is to boot off of a floppy disk
  851.   and prepare another bootable floppy (such as `make zdisk' would do).
  852.   You need to know where your root (/) filesystem is and what type it is
  853.   (e.g. second extended, minix). In the example below, you also need to
  854.   know what filesystem your /usr/src/linux source tree is on, its type,
  855.   and where it is normally mounted.
  856.  
  857.  
  858.  
  859.   In the following example, / is /dev/hda1, and the filesystem which
  860.   holds /usr/src/linux is /dev/hda3, normally mounted at /usr. Both are
  861.   second extended filesystems. The working kernel image in
  862.   /usr/src/linux/arch/i386/boot is called zImage.
  863.  
  864.  
  865.   The idea is that if there is a functioning zImage, it is possible to
  866.   use that for the new floppy. Another alternative, which may or may not
  867.   work better (it depends on the particular method in which you messed
  868.   up your system) is discussed after the example.
  869.  
  870.  
  871.   First, boot from a boot/root disk combo or rescue disk, and mount the
  872.   filesystem which contains the working kernel image:
  873.  
  874.  
  875.  
  876.   mkdir /mnt
  877.   mount -t ext2 /dev/hda3 /mnt
  878.  
  879.  
  880.  
  881.   If mkdir tells you that the directory already exists, just ignore it.
  882.   Now, cd to the place where the working kernel image was. Note that
  883.  
  884.   /mnt + /usr/src/linux/arch/i386/boot - /usr = /mnt/src/linux/arch/i386/boot
  885.  
  886.  
  887.   Place a formatted disk in drive ``A:'' (not your boot or root disk!),
  888.   dump the image to the disk, and configure it for your root filesystem:
  889.  
  890.  
  891.  
  892.   cd /mnt/src/linux/arch/i386/boot
  893.   dd if=zImage of=/dev/fd0
  894.   rdev /dev/fd0 /dev/hda1
  895.  
  896.  
  897.  
  898.   cd to / and unmount the normal /usr filesystem:
  899.  
  900.  
  901.   cd /
  902.   umount /mnt
  903.  
  904.  
  905.  
  906.   You should now be able to reboot your system as normal from this
  907.   floppy.  Don't forget to run lilo (or whatever it was that you did
  908.   wrong) after the reboot!
  909.  
  910.  
  911.   As mentioned above, there is another common alternative. If you
  912.   happened to have a working kernel image in / (/vmlinuz for example),
  913.   you can use that for a boot disk. Supposing all of the above
  914.   conditions, and that my kernel image is /vmlinuz, just make these
  915.   alterations to the example above: change /dev/hda3 to /dev/hda1 (the /
  916.   filesystem), /mnt/src/linux to /mnt, and if=zImage to if=vmlinuz. The
  917.   note explaining how to derive /mnt/src/linux may be ignored.
  918.  
  919.  
  920.  
  921.   7.6.  It says `warning: bdflush not running'
  922.  
  923.  
  924.  
  925.   This can be a severe problem. Starting with a kernel release after 1.0
  926.   (around 20 Apr 1994), a program called `update' which periodically
  927.   flushes out the filesystem buffers, was upgraded/replaced. Get the
  928.   sources to `bdflush' (you should find it where you got your kernel
  929.   source), and install it (you probably want to run your system under
  930.   the old kernel while doing this). It installs itself as `update' and
  931.   after a reboot, the new kernel should no longer complain.
  932.  
  933.  
  934.  
  935.   7.7.  It says weird things about obsolete routing requests
  936.  
  937.  
  938.   Get new versions of the route program and any other programs which do
  939.   route manipulation.  /usr/include/linux/route.h  (which is actually a
  940.   file in /usr/src/linux) has changed.
  941.  
  942.  
  943.  
  944.   7.8.  Firewalling not working in 1.2.0
  945.  
  946.   Upgrade to at least version 1.2.1.
  947.  
  948.  
  949.  
  950.   8.  Modules
  951.  
  952.   Loadable kernel modules can save memory and ease configuration. The
  953.   scope of modules has grown to include filesystems, ethernet card
  954.   drivers, tape drivers, printer drivers, and more.
  955.  
  956.  
  957.  
  958.   8.1.  Installing the module utilities
  959.  
  960.   The module utilities are available from wherever you got your kernel
  961.   source as modules-x.y.z.tar.gz; choose the highest patchlevel x.y.z
  962.   that is equal to or below that of your current kernel. Unpack it with
  963.   `tar zxvf modules-x.y.z.tar.gz', cd to the directory it creates
  964.   (modules-x.y.z), look over the README, and carry out its installation
  965.   instructions (which is usually something simple, such as make
  966.   install). You should now have the programs insmod, rmmod, ksyms,
  967.   lsmod, genksyms, modprobe, and depmod in /sbin. If you wish, test out
  968.   the utilities with the ``hw'' example driver in insmod; look over the
  969.   INSTALL file in that subdirectory for details.
  970.  
  971.   insmod inserts a module into the running kernel. Modules usually have
  972.   a .o extension; the example driver mentioned above is called
  973.   drv_hello.o, so to insert this, one would say `insmod drv_hello.o'. To
  974.   see the modules that the kernel is currently using, use lsmod. The
  975.   output looks like this:
  976.  
  977.   blah# lsmod
  978.   Module:        #pages:  Used by:
  979.   drv_hello          1
  980.  
  981.  
  982.   `drv_hello' is the name of the module, it uses one page (4k) of mem-
  983.   ory, and no other kernel modules depend on it at the moment. To remove
  984.   this module, use `rmmod drv_hello'. Note that rmmod wants a module
  985.   name, not a filename; you get this from lsmod's listing. The other
  986.   module utilities' purposes are documented in their manual pages.
  987.  
  988.  
  989.  
  990.  
  991.   8.2.  Modules distributed with the kernel
  992.  
  993.   As of version 1.2.2, many filesystems, a few SCSI drivers, several
  994.   ethernet adapter drivers, and other odds and ends are loadable as
  995.   modules. To use them, first make sure that you don't configure them
  996.   into the regular kernel; that is, don't say y to it during `make
  997.   config'.  Compile a new kernel and reboot with it. Then, cd to
  998.   /usr/src/linux again, and do a `make modules'. This compiles all of
  999.   the modules which you did not specify in the kernel configuration, and
  1000.   places links to them in /usr/src/linux/modules.  You can use them
  1001.   straight from that directory or execute `make modules_install', which
  1002.   installs them in /lib/modules/x.y.z, where x.y.z is the kernel
  1003.   release.
  1004.  
  1005.  
  1006.   This can be especially handy with filesystems. You may not use the
  1007.   minix or msdos filesystems frequently. For example, if I encountered
  1008.   an msdos (shudder) floppy, I would insmod
  1009.   /usr/src/linux/modules/msdos.o, and then rmmod msdos when finished.
  1010.   This procedure saves about 50k of RAM in the kernel during normal
  1011.   operation. A small note is in order for the minix filesystem: you
  1012.   should always configure it directly into the kernel for use in
  1013.   ``rescue'' disks.
  1014.  
  1015.  
  1016.  
  1017.   9.  Other configuration options
  1018.  
  1019.   This section contains descriptions of selected kernel configuration
  1020.   options (in make config) which are not listed in the configuration
  1021.   section.  Most device drivers are not listed here.
  1022.  
  1023.  
  1024.  
  1025.   9.1.  General setup
  1026.  
  1027.  
  1028.   Normal floppy disk support - is exactly that. You may wish to read
  1029.   over the file drivers/block/README.fd; this is especially important
  1030.   for IBM Thinkpad users.
  1031.  
  1032.  
  1033.   XT harddisk support - if you want to use that 8 bit XT controller
  1034.   collecting dust in the corner.
  1035.  
  1036.  
  1037.   PCI bios support - if you have PCI, you may want to give this a shot;
  1038.   be careful, though, as some old PCI motherboards could crash with this
  1039.   option. More information about the PCI bus under linux is found in the
  1040.   PCI-HOWTO.
  1041.  
  1042.  
  1043.   Kernel support for ELF binaries - ELF is an effort to allow binaries
  1044.   to span architectures and operating systems; linux seems to be headed
  1045.   in that direction.
  1046.  
  1047.  
  1048.   Set version information on all symbols for modules - in the past,
  1049.   kernel modules were recompiled along with every new kernel. If you say
  1050.   y, it will be possible to use modules compiled under a different
  1051.   patchlevel. Read README.modules for more details.
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.   9.2.  Networking options
  1058.  
  1059.   Networking options are described in the NET-2-HOWTO.
  1060.  
  1061.  
  1062.   10.  Tips and tricks
  1063.  
  1064.  
  1065.  
  1066.   10.1.  Redirecting output of the make or patch commands
  1067.  
  1068.  
  1069.   If you would like logs of what those `make' or `patch' commands did,
  1070.   you can redirect output to a file. First, find out what shell you're
  1071.   running: `grep root /etc/passwd' and look for something like
  1072.   `/bin/csh'.
  1073.  
  1074.  
  1075.   If you use sh or bash,
  1076.  
  1077.   (command) 2>&1 | tee (output file)
  1078.  
  1079.  
  1080.   will place a copy of (command)'s output in the file `(output file)'.
  1081.  
  1082.  
  1083.   For csh or tcsh, use
  1084.  
  1085.   (command) |& tee (output file)
  1086.  
  1087.  
  1088.  
  1089.  
  1090.   For rc (Note: you probably do not use rc) it's
  1091.  
  1092.   (command) >[2=1] | tee (output file)
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.   10.2.  Conditional kernel install
  1099.  
  1100.   Other than using floppy disks, there are several methods of testing
  1101.   out a new kernel without touching the old one. Unlike many other Unix
  1102.   flavors, LILO has the ability to boot a kernel from anywhere on the
  1103.   disk (if you have a large (500 MB or above) disk, please read over the
  1104.   LILO documentation on how this may cause problems). So, if you add
  1105.   something similar to
  1106.  
  1107.   image = /usr/src/linux/arch/i386/zImage
  1108.       label = new_kernel
  1109.  
  1110.  
  1111.   to the end of your LILO configuration file, you can choose to run a
  1112.   newly compiled kernel without touching your old /vmlinuz (after run-
  1113.   ning lilo, of course). The easiest way to tell LILO to boot a new ker-
  1114.   nel is to press the shift key at bootup time (when it says LILO on the
  1115.   screen, and nothing else), which gives you a prompt.  At this point,
  1116.   you can enter `new_kernel' to boot the new kernel.
  1117.  
  1118.   If you wish to keep several different kernel source trees on your
  1119.   system at the same time (this can take up a lot of disk space; be
  1120.   careful), the most common way is to name them /usr/src/linux-x.y.z,
  1121.   where x.y.z is the kernel version. You can then ``select'' a source
  1122.   tree with a symbolic link; for example, `ln -sf linux-1.2.2
  1123.   /usr/src/linux' would make the 1.2.2 tree current. Before creating a
  1124.   symbolic link like this, make certain that the last argument to ln is
  1125.   not a real directory (old symbolic links are fine); the result will
  1126.   not be what you expect.
  1127.  
  1128.  
  1129.  
  1130.   10.3.  Kernel updates
  1131.  
  1132.   Russell Nelson (nelson@crynwr.com) summarizes the changes in new
  1133.   kernel releases. These are short, and you might like to look at them
  1134.   before an upgrade. They are available with anonymous ftp from
  1135.   ftp.emlist.com in pub/kchanges or through the URL
  1136.  
  1137.   http://www.nvg.unit.no/linux-changes/index.html
  1138.  
  1139.  
  1140.  
  1141.  
  1142.  
  1143.   11.  Misc
  1144.  
  1145.  
  1146.  
  1147.   11.1.  Author
  1148.  
  1149.  
  1150.   The author and maintainer of the Linux Kernel-HOWTO is Brian Ward
  1151.   (ward@blah.tu-graz.ac.at). Please send me any comments, additions,
  1152.   corrections, or computers. Corrections are, in particular, the most
  1153.   important to me. You can look at my `home page' at one of these URLs:
  1154.  
  1155.   http://www.math.psu.edu/ward/
  1156.   http://blah.tu-graz.ac.at/~ward/
  1157.  
  1158.  
  1159.  
  1160.  
  1161.   Even though I try to be attentive as possible with mail, please
  1162.   remember that I get a lot of mail per day, so it may take a little
  1163.   time to get back to you. Especially when emailing me with a question,
  1164.   please try extra hard to be clear and detailed in your message. I do
  1165.   not care if you ask simple questions; remember, if you don't ask, you
  1166.   may never get an answer! I'd like to thank everyone who has given me
  1167.   feedback.
  1168.  
  1169.  
  1170.   Version -0.1 was written on October 3, 1994; this document is
  1171.   available in SGML, PostScript, TeX, roff, and plain-text formats.
  1172.  
  1173.  
  1174.  
  1175.   11.2.  To do
  1176.  
  1177.   The ``Tips and tricks'' section is a little small. I hope to expand on
  1178.   it with suggestions from others.
  1179.  
  1180.   So is ``Additional packages.''
  1181.  
  1182.   More debugging/crash recovery info needed.
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.   11.3.  Contributions
  1190.  
  1191.   A small part of Linus' README (kernel hacking options) is inclusive.
  1192.   (Thanks, Linus!)
  1193.  
  1194.   uc@brian.lunetix.de (Ulrich Callmeier): patch -s and xargs.
  1195.  
  1196.   quinlan@yggdrasil.com (Daniel Quinlan): corrections and additions in
  1197.   many sections.
  1198.  
  1199.   nat@nataa.frmug.fr.net (Nat MAKAREVITCH): mrproper
  1200.  
  1201.   boldt@math.ucsb.edu (Axel Boldt): collected descriptions of kernel
  1202.   configuration options on the net; then provided me with the list
  1203.  
  1204.   lembark@wrkhors.psyber.com (Steve Lembark): multiple boot suggestion
  1205.  
  1206.   kbriggs@earwax.pd.uwa.edu.au (Keith Briggs): some corrections and
  1207.   suggestions
  1208.  
  1209.   Eric.Dumas@emi.u-bordeaux.fr (Eric Dumas): did a French translation
  1210.  
  1211.   donahue@tiber.nist.gov (Michael J Donahue): typos, winner of the
  1212.   ``sliced bread competition''
  1213.  
  1214.   The people who have sent me mail with questions and problems have also
  1215.   been quite helpful.
  1216.  
  1217.  
  1218.  
  1219.   11.4.  Copyright notice and copying
  1220.  
  1221.   Copyright (c) Brian Ward, 1994, 1995.
  1222.  
  1223.   This document may be distributed in any medium as long as it and this
  1224.   notice remain unaltered. Permission is granted for translation into
  1225.   any language, so long as the translator's name is added to the
  1226.   document.  There is no warranty on this document and its contents; no
  1227.   one may be held liable for any unfortunate outcome of its content.
  1228.  
  1229.  
  1230.   Commercial redistribution is allowed and encouraged; however, it is
  1231.   strongly recommended that the redistributor contact the author before
  1232.   the redistribution, in the interest of keeping things up-to-date. The
  1233.   same is true for translations.
  1234.